<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
// {
//   function* gen() {
//     yield 'hello'
//     yield 'world'
//     return 'ending'
//   }

//   let it = gen()

//   it.next()   // {value: "hello", done: false}
//   it.next()   // {value: "world", done: false}
//   it.next()   // {value: "ending", done: true}
//   it.next()   // {value: undefined, done: true}
// }
function fn(){ // 定义一个Generator函数
yield 'hello'
yield 'world'
return 'end'
}
var f1 =fn(); // 调用Generator函数
console.log(f1); // fn {[[GeneratorStatus]]: “suspended”}
console.log(f1.next()); // {value: “hello”, done: false}
console.log(f1.next()); // {value: “world”, done: false}
console.log(f1.next()); // {value: “end”, done: true}
console.log(f1.next()); // {value: undefined, done: true}

    </script>
</body>
</html>